﻿using Inaction.ServiceContract;
using Inaction.ServiceProxy;
using System.ServiceModel;

namespace Inaction.Host
{
    [ServiceContract]
    public interface IHost
    {
        [OperationContract]
        [ServiceKnownType(typeof(Request))]
        [ServiceKnownType(typeof(Response))]
        Response Login(Request request);
        [OperationContract]
        [ServiceKnownType(typeof(Request))]
        [ServiceKnownType(typeof(Response))]
        Response Query(Request request);
        [OperationContract]
        [ServiceKnownType(typeof(Request))]
        [ServiceKnownType(typeof(Response))]
        Response Save(Request request);
        [OperationContract]
        [ServiceKnownType(typeof(Request))]
        [ServiceKnownType(typeof(Response))]
        Response Excute(Request request);
        [OperationContract]
        [ServiceKnownType(typeof(Request))]
        [ServiceKnownType(typeof(Response))]
        Response Invoke(Request request);
    }

    public static class IHostExtend
    {
        public static void RunPlugins(this IHost host)
        {
            AppConfig.Instance.RunLocation = RunLocation.Server;
            var manager = ServiceContainer.GetService<IServicePluginManager>();
            if (manager != null)
            {
                manager.RunPlugins();
            }
        }
    }
}